import sympy as sym
from fractions import Fraction
import math
x=sym.Symbol('x')
y=sym.Symbol('y')
pi=sym.Symbol('PI')
pi=sym.pi
t=sym.Symbol('t')
p=sym.Symbol('p')
nu=sym.Symbol('nu')

f1_a=-2*pi*(x**2*y**2+sym.exp(-y))*sym.sin(2*pi*t)+(-2*nu*x**2-2*nu*y**2-nu*sym.exp(-y)+pi**2*sym.cos(pi*x)*sym.cos(2*pi*y))*sym.cos(2*pi*t)
f2_a=-2*pi*(-2.0/3.0*x*y**3+2-pi*sym.sin(pi*x))*sym.sin(2*pi*t)+(4*nu*x*y-nu*pi**3*sym.sin(pi*x)+2*pi*(2-pi*sym.sin(pi*x))*sym.sin(2*pi*y))*sym.cos(2*pi*t)

u1=(x**2*y**2+sym.exp(-y))*sym.cos(2*pi*t)
print("u1,x=0:\t{}".format(u1.subs(x,0)))
print("u1,x=1:\t{}".format(u1.subs(x,1)))
print("u1,y=-0.25:\t{}".format(u1.subs(y,-0.25)))
print("u1,y=0:\t{}".format(u1.subs(y,0)))
print("u1,t=0:\t{}".format(u1.subs(t,0)))

u2=(-Fraction(2,3)*x*y**3+2-pi*sym.sin(pi*x))*sym.cos(2*pi*t)
print("u2,x=0:\t{}".format(u2.subs(x,0)))
print("u2,x=1:\t{}".format(u2.subs(x,1)))
print("u2,y=-0.25:\t{}".format(u2.subs(y,-0.25)))
print("u2,y=0:\t{}".format(u2.subs(y,0)))
print("u2,t=0:\t{}".format(u2.subs(t,0)))

print("du1/dx+du2/dy={}".format(u2.diff(y,1)+u1.diff(x,1)))
p=-(2.0-pi*sym.sin(pi*x))*sym.cos(2*pi*y)*sym.cos(2*pi*t)
print("p,t=0:\t{}".format(p.subs(t,0)))
print("p,x=0,y=0:\t{}".format(p.subs(x,0).subs(y,0)))



f1=u1.diff(t,1)+u1*u1.diff(x,1)+u2*u1.diff(y,1)+p.diff(x,1)-nu*(u1.diff(x,2)+u1.diff(y,2))
f2=u2.diff(t,1)+u1*u2.diff(x,1)+u2*u2.diff(y,1)+p.diff(y,1)-nu*(u2.diff(x,2)+u2.diff(y,2))
print("f1={}".format((f1)))
print("f2={}".format((f2)))
print(sym.simplify(f1-(u1*u1.diff(x,1)+u2*u1.diff(y,1))-f1_a))
print(sym.simplify(f2-(u1*u2.diff(x,1)+u2*u2.diff(y,1))-f2_a))




